<html>
<head><meta charset="utf-8"><title>Equality and ordering on Symbols · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Equality.20and.20ordering.20on.20Symbols.html">Equality and ordering on Symbols</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240092856"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Equality%20and%20ordering%20on%20Symbols/near/240092856" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Richard Cobbe <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Equality.20and.20ordering.20on.20Symbols.html#240092856">(May 24 2021 at 18:38)</a>:</h4>
<p>I've got the following struct definition:</p>
<div class="codehilite"><pre><span></span><code>pub struct DllImport {
    pub name: rustc_span::symbol::Symbol,
    pub ordinal: Option&lt;u16&gt;,
}
</code></pre></div>
<p>and I'm trying to define an implementation of <code>Ord</code> for <code>DllImport</code> that defines an ordering that's deterministic across compilations.  I know that Symbol's native ordering isn't deterministic, and that I have to compare <code>name.as_str()</code> instead; that's straightforward enough.</p>
<p>To implement<code>Eq</code> for <code>DllImport</code>, though, can I just use <code>Symbol</code>'s native equality, or do I need to compare <code>name.as_str()</code> there as well?  Equivalently: does <code>sym1.as_str() == sym2.as_str()</code> imply <code>sym1 == sym2</code>?  (I'm assuming the inverse is true.)</p>



<a name="240094168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Equality%20and%20ordering%20on%20Symbols/near/240094168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Equality.20and.20ordering.20on.20Symbols.html#240094168">(May 24 2021 at 18:48)</a>:</h4>
<p>yes, that should work</p>



<a name="240094202"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Equality%20and%20ordering%20on%20Symbols/near/240094202" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Equality.20and.20ordering.20on.20Symbols.html#240094202">(May 24 2021 at 18:48)</a>:</h4>
<p><code>sym1 == sym2</code> exactly when <code>sym1.as_str() == sym2.as_str()</code> AFAIK</p>



<a name="240094536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Equality%20and%20ordering%20on%20Symbols/near/240094536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Richard Cobbe <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Equality.20and.20ordering.20on.20Symbols.html#240094536">(May 24 2021 at 18:51)</a>:</h4>
<p>Excellent, thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>